package top.jiangqiang.qianyi.web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qianyi.business.model.request.UserInfoListRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoPageRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoSaveRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoUpdateRequest;
import top.jiangqiang.qianyi.business.model.response.UserInfoDetailResponse;
import top.jiangqiang.qianyi.business.model.response.UserInfoListResponse;
import top.jiangqiang.qianyi.business.model.response.UserInfoPageResponse;
import top.jiangqiang.qianyi.business.service.UserInfoService;
import top.jiangqiang.qianyi.common.base.controller.BaseController;
import top.jiangqiang.qianyi.common.base.model.response.PageResult;
import top.jiangqiang.qianyi.common.base.model.response.Result;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;
import top.jiangqiang.qianyi.common.constants.log.SysLogType;
import top.jiangqiang.qianyi.common.log.annotations.Log;

import java.util.List;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author JiangQiang
 * @since 2024-06-03
 */
@Tag(name = "用户信息接口", description = "")
@RestController
@RequiredArgsConstructor
@RequestMapping(GlobalConstants.AdminRequestURLConstants.ADMIN_CONTROLLER_PREFIX + "/userInfo")
public class AdminUserInfoController extends BaseController {
    private final UserInfoService userInfoService;

    @GetMapping("/page")
    @Operation(summary = "用户信息分页查询")
    @Log(value = "用户信息分页查询", type = SysLogType.PAGE)
    public Result<PageResult<UserInfoPageResponse>> page(@Validated @ParameterObject UserInfoPageRequest request) {
        return userInfoService.page(request);
    }

    @GetMapping("/list")
    @Operation(summary = "用户信息全表查询")
    @Log(value = "用户信息全表查询", type = SysLogType.LIST)
    public Result<List<UserInfoListResponse>> list(@Validated @ParameterObject UserInfoListRequest request) {
        return userInfoService.list(request);
    }

    @PostMapping
    @Operation(summary = "用户信息新增")
    @Log(value = "用户信息新增", type = SysLogType.ADD)
    public Result<Void> save(@Validated UserInfoSaveRequest request) {
        return userInfoService.add(request);
    }

    @PutMapping
    @Operation(summary = "用户信息修改")
    @Log(value = "用户信息修改", type = SysLogType.UPDATE)
    public Result<Void> update(@Validated UserInfoUpdateRequest request) {
        return userInfoService.update(request);
    }

    @GetMapping("/{id}")
    @Operation(summary = "用户信息详情")
    @Log(value = "用户信息详情", type = SysLogType.DETAIL)
    public Result<UserInfoDetailResponse> detail(@NotNull(message = "ID不能为空") @PathVariable("id") Long id) {
        return userInfoService.detail(id);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "用户信息删除")
    @Log(value = "用户信息删除", type = SysLogType.DELETE)
    public Result<Void> delete(@NotNull(message = "ID不能为空") @PathVariable("id") Long id) {
        return userInfoService.delete(id);
    }

}
